package com.baosight.innerinterface.service;

import java.util.HashMap;
import java.util.Map;

import com.baosight.innerinterface.domain.JH21;
import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;

/**
 * 通过接口获取年生产计划
 * <p>Title: ServiceYearPlan.java</p>
 * <p>Description:通过接口获取年生产计划 </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author lhx
 * @version 1.0
 * <pre>Histroy:
 *          2016-8-19 10:58:19  lhx  Create
 *</pre>
 */
public class ServiceYearPlan{
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	public ServiceYearPlan(){
	}
	/**
	 * 通过接口获取矿年计划数据
	 * @param inInfo 综合生产计划系统含有“result” block的EiInfo
	 * @param _dom 综合生产计划系统年计划对象bean
	 * @return void
	 */
	public void insert(EiInfo inInfo,JH21 _dom) {
		EiBlock eiBlock = inInfo.getBlock("detail");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		Map<String,String> insMap=new HashMap<String,String>();
		String fdForeignId="";//矿井id
		String fdItem="";//指标名称
		String fdUnit="";//计量单位
		int fdNo=0;//序号
		double fdSurplusLength=0;//年计划
		String fdYearGetway="";//年份
		String fdItemType="";//指标类型
		for (int i = 0; i < rowcount; i++) {
			int num=1;
			_dom.fromMap(eiBlock.getRow(i));
			fdForeignId=_dom.getDepartmentCode();
			fdItem="原煤产量";
			fdUnit="万t";
			fdNo=num;
			fdSurplusLength=_dom.getCoalPlanAmount().doubleValue();
			fdYearGetway=_dom.getPlanYear();
			//先删除要插入的年份、矿的记录
			Map<String,String> params = new HashMap<String,String>();
			params.put("fdYearGetway", fdYearGetway);//年份
			params.put("fdForeignId", fdForeignId);//矿id
			dao.delete("ZMCPYearPlanZB.clean", params);
			//然后再进行插入
			fdItemType="产量指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="发热量";
			fdUnit="千卡/kg";
			fdNo=num;
			fdSurplusLength=_dom.getCalorificValuePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="产量指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="保护层面积";
			fdUnit="万平方米";
			fdNo=num;
			fdSurplusLength=_dom.getProtectPlanAmount().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="产量指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="厚保面积比";
			fdUnit="1：X";
			fdNo=num;
			fdSurplusLength=_dom.getThickAreaValuePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="产量指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="掘进总进尺";
			fdUnit="m";
			fdNo=num;
			fdSurplusLength=_dom.getDrivingPlanAmount().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="进尺指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="生产进尺";
			fdUnit="m";
			fdNo=num;
			fdSurplusLength=_dom.getGotoDrivingValuePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="进尺指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="延深进尺";
			fdUnit="m";
			fdNo=num;
			fdSurplusLength=_dom.getExtendDrivingValuePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="进尺指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="综掘进尺";
			fdUnit="m";
			fdNo=num;
			fdSurplusLength=_dom.getNumbercolumn1().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="进尺指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="生产掘进率";
			fdUnit="m/万吨";
			fdNo=num;
			fdSurplusLength=_dom.getPorductDrivingRatePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="进尺指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="延深掘进率";
			fdUnit="m/万吨";
			fdNo=num;
			fdSurplusLength=_dom.getExpandRatePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="进尺指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);

			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="抽采钻尺";
			fdUnit="万m";
			fdNo=num;
			fdSurplusLength=_dom.getDrawingValuePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="抽采指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="瓦斯抽采量";
			fdUnit="万立方米";
			fdNo=num;
			fdSurplusLength=_dom.getGasoutputPlanAmount().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="抽采指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="瓦斯利用量";
			fdUnit="万立方米";
			fdNo=num;
			fdSurplusLength=_dom.getGasusePlanAmount().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="抽采指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="万吨钻尺率";
			fdUnit="米/万吨";
			fdNo=num;
			fdSurplusLength=_dom.getMineDrivingRatePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="抽采指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="万吨抽采量";
			fdUnit="万立方米/万吨";
			fdNo=num;
			fdSurplusLength=_dom.getCoalTeamValuePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="抽采指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="人均原煤产量";
			fdUnit="吨/人.年";
			fdNo=num;
			fdSurplusLength=_dom.getCoalPerPlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="效率指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="人均掘进进尺";
			fdUnit="米/人.年";
			fdNo=num;
			fdSurplusLength=_dom.getDrivingPerPlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="效率指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="洗煤量";
			fdUnit="t";
			fdNo=num;
			fdSurplusLength=_dom.getCoalWashingValuePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="其他指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="入洗量";
			fdUnit="t";
			fdNo=num;
			fdSurplusLength=_dom.getGoWashingValuePlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="其他指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
			num++;
			//_dom.fromMap(eiBlock.getRow(i));
			//fdForeignId=_dom.getDepartmentCode();
			fdItem="煤炭销售量";
			fdUnit="t";
			fdNo=num;
			fdSurplusLength=_dom.getCoalSaleAmountPlan().doubleValue();
			//fdYearGetway=_dom.getPlanYear();
			fdItemType="其他指标";
			insMap.put( "fdForeignId", fdForeignId);
			insMap.put( "fdItem", fdItem);
			insMap.put( "fdUnit", fdUnit);
			insMap.put( "fdNo", fdNo+"");
			insMap.put( "fdSurplusLength", fdSurplusLength+"");
			insMap.put( "fdYearGetway", fdYearGetway);
			insMap.put( "fdItemType", fdItemType);
			insMap.put("fdKeyId",TablePk.getInstance().getNextValue("T_CP_YEAR_PLAN_ZB"));
			dao.insert("ZMCPYearPlanZB.insert", insMap);
	    }
	}
}
